package example.param;

import com.mysql.jdbc.StringUtils;
import example.constant.PreConditionsCheck;
import example.constant.ResponseEnum;


import java.io.Serializable;

/**
 * Created by zhangshi on 2017/4/17.
 */
public abstract class Param implements Serializable{
    private String searchKey;

    public String getSearchKey() {
        return searchKey;
    }

    public void setSearchKey(String searchKey) {
        this.searchKey = searchKey;
    }

    protected void checkBlank(String input){
        PreConditionsCheck.checkArgument(StringUtils.isNullOrEmpty(input), ResponseEnum.PARAMETER_ERROR);
    }

    protected void checkLength(String input, int minLength, int maxLength, String code, String msg){
        PreConditionsCheck.checkArgument(input.length() < minLength, code, msg);
        PreConditionsCheck.checkArgument(input.length() > maxLength, code, msg);
    }
    protected void checkLength(String input, int minLength, int maxLength){
        PreConditionsCheck.checkArgument(input.length() < minLength, ResponseEnum.PARAMETER_ERROR);
        PreConditionsCheck.checkArgument(input.length() > maxLength, ResponseEnum.PARAMETER_ERROR);
    }

    // null
    protected void checkNull(Object input){
        PreConditionsCheck.checkArgument(input == null, ResponseEnum.PARAMETER_ERROR);
    }


    // 正数
    protected void checkPositive(int input){
        PreConditionsCheck.checkArgument(input <= 0, ResponseEnum.PARAMETER_ERROR);
    }

    public abstract void check();
}
